# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import List
from pydantic import TypeAdapter
from common.models.draws import DrawsPromptCategoryModel
from common.models.draws import DrawsPromptExampleModel
from common.models.draws import DrawsPromptLexiconModel
from apps.api.schemas.apply.draws import prompt_schema as schema


class DrawsPromptService:
    """ 绘画词库服务类 """

    @classmethod
    async def category(cls, engine: str) -> List[schema.DrawsPromptCategoryVo]:
        """
        词库分类列表

        Args:
            engine (str): 绘图引擎(mj|sd|doubao|dalle)

        Returns:
            List[schema.DrawsPromptCategoryVo]

        Author:
            zero
        """
        lists = await (DrawsPromptCategoryModel
                       .filter(engine=engine)
                       .filter(is_delete=0)
                       .order_by("-sort", "-id")
                       .all())

        return [TypeAdapter(schema.DrawsPromptCategoryVo).validate_python(item.__dict__) for item in lists]

    @classmethod
    async def lexicon(cls, engine: str, cid: int) -> List[schema.DrawsPromptLexiconVo]:
        """
        词库词汇列表

        Args:
            engine (str): 绘图引擎(mj|sd|doubao|dalle)
            cid (int): 分类ID

        Returns:
            List[schema.DrawsPromptLexiconVo]

        Author:
            zero
        """
        lists = await (DrawsPromptLexiconModel
                       .filter(engine=engine)
                       .filter(category_id=cid)
                       .filter(is_delete=0)
                       .order_by("-sort", "-id")
                       .all())

        return [TypeAdapter(schema.DrawsPromptLexiconVo).validate_python(item.__dict__) for item in lists]

    @classmethod
    async def example(cls, engine: str) -> List[schema.DrawsPromptExampleVo]:
        """
        词库示例列表

        Args:
            engine (str): 绘图引擎(mj|sd|doubao|dalle)

        Returns:
            List[schema.DrawsPromptExampleVo]

        Author:
            zero
        """
        lists = await (DrawsPromptExampleModel
                       .filter(engine=engine)
                       .filter(is_delete=0)
                       .order_by("-sort", "-id")
                       .all())

        return [TypeAdapter(schema.DrawsPromptExampleVo).validate_python(item.__dict__) for item in lists]
